package com.itany.shop.servlet;

import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.ProductService;
import com.itany.shop.vo.Cart;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 黄衡熙
 * @version 1.0
 */
@WebServlet("*.cart")
public class CartServlet extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String path = req.getServletPath();
        switch (path) {
            case "/add.cart":
                addCart(req, resp);
                break;
            case "/removeById.cart":
                removeById(req,resp);
                break;
            case "/removeByIds.cart":
                removeByIds(req,resp);
                break;
            case "modify.cart":
                modefyCart(req,resp);
                break;
            case "clean.cart":
                cleanCart(req,resp);
                break;
            default:
                PrintWriter out = resp.getWriter();
                out.println("<h1 style='color:red;'>对不起,您访问的资源有误,请检查请求是否正确</h1>");
        }
    }
    protected void addCart(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService productService = (ProductService) ObjectFactory.getObject("productService");
        String id=req.getParameter("id");
//        从session中获取购物车
        Cart cart= (Cart) req.getSession().getAttribute("cart");



    }
    protected void removeById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService productService = (ProductService) ObjectFactory.getObject("productService");

    }
    protected void removeByIds(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService productService = (ProductService) ObjectFactory.getObject("productService");

    }
    protected void modefyCart(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService productService = (ProductService) ObjectFactory.getObject("productService");

    }
    protected void cleanCart(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService productService = (ProductService) ObjectFactory.getObject("productService");

    }
}
